package lockx

import (
	"sync"
)

type OnceMap struct {
	sync.Once // 仅仅只执行一次Do
	data      map[string]int
}

func NewOnceMap() *OnceMap {
	return &OnceMap{
		data: make(map[string]int),
	}

}

func (m *OnceMap) OnceLoadData() {
	m.Do(func() {
		lisy := []string{"1", "2", "3", "4", "5", "6"}
		for _, value := range lisy {
			_, ok := m.data[value]
			if !ok {
				m.data[value] = 0
			}
			m.data[value]++
		}
	})
}
func (m *OnceMap) LoadData() {
	lisy := []string{"1", "2", "3", "4", "5", "6"}
	for _, value := range lisy {
		_, ok := m.data[value]
		if !ok {
			m.data[value] = 0
		}
		m.data[value]++
	}
}
